home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: Integral promotion problem
- Date: 10 Mar 1996 10:32:14 -0600
- Organization: Los Alamos National Laboratory
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4hv06e$jb9@solutions.solon.com>
- References: <4hqedq$1mj@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4hqedq$1mj@solutions.solon.com>
- johnb@pivotal-dm.ccmail.compuserve.com (John Bain) writes:
-
- JB: Hi,
- JB:
- JB: I thought I understood integral promotion, but the following example has
- JB: me puzzled.
- <snip>
- JB: unsigned short s = 0xFFFF;
- <snip>
- JB: int i = ~s;
- JB:
- JB: printf ("%x %x\n", i, (int)~s);
- <snip>
- JB: if ((int)~s)
- JB: printf("(int)~s - NonZero\n");
- JB: else
- JB: printf("(int)~s - Zero\n");
- <snip>
- JB: When compiled on an implementation with 32-bit 2's complement ints I get
- JB: the following output:
- JB:
- JB: -------------------
- JB: ffff0000 ffff0000
- JB: i - NonZero
- JB: (int)~s - Zero
- JB: ------------------
- JB:
- JB: The hex values and the result of the first "if" are the "surprising"
- JB: results I was expecting. However, the result of the second "if" has me
- JB: confused.
- JB:
- JB: What am I missing?
- JB:
-
- Compiler error?
-
- JB: (In case it's relevent, the implementation defines the conversion of an
- JB: unsigned integer to a signed integer, when the unsigned value cannot be
- JB: represented in the signed integer, as being performed by truncation of
- JB: the most significant bits if the signed integer is shorter, and then
- JB: interpreting the remaining bits as a 2's complement integer.)
-
- Why should that be relevant? What am I missing?
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-